<template>
    <div>
        <div class="head">
            <span class="iconfont icon-arrow-left-bold" @click="gotoUp"></span>
            <div class="title">VIP会员</div>
        </div>
        <div class="container">
            <div class="info">
                <div class="left">
                    <img :src="info.avatar" alt="" />
                </div>
                <div class="right">
                    <div>
                        <div>您的{{ name }}{{ info.role_expired_at }}到期</div>
                        <div>购买后将会有效期顺延</div>
                    </div>
                </div>
            </div>
            <div class="item-box">
                <div :class="{ item, active: activeid == item.id }" v-for="item in arr" :key="item.id" @click="addA(item.id)">
                    <div class="name">{{ item.name }}</div>
                    <div class="money"><span>￥</span>{{ item.charge }}</div>
                    <div class="txt">所有视频免费看</div>
                </div>
            </div>
            <div class="bottom-bar" @click="pay(activeid, arr)">购买会员</div>
        </div>
    </div>
</template>

<script>
import { Toast } from "vant";
export default {
    data() {
        return {
            info: {},
            name: "",
            arr: [],
            activeid: 4,
        };
    },
    methods: {
        gotoUp() {
            this.$router.push({
                path: "/user",
                query: {},
            });
        },
        addA(id) {
            this.activeid = id;
        },
        pay(activeid, item) {
            if (activeid != 1 && activeid != 2 && activeid != 3) {
                Toast.fail("请选择需要购买的会员");
            } else if (activeid == 1) {
                this.$router.push({
                    path: "/buyvip",
                    query: {
                        goods_id: item[0].id,
                        goods_name: item[0].name,
                        goods_label: "VIP会员",
                        goods_charge: item[0].charge,
                        goods_type: "role",
                    },
                });
            } else if (activeid == 2) {
                this.$router.push({
                    path: "/buyvip",
                    query: {
                        goods_id: item[1].id,
                        goods_name: item[1].name,
                        goods_label: "VIP会员",
                        goods_charge: item[1].charge,
                        goods_type: "role",
                    },
                });
            } else if (activeid == 3) {
                this.$router.push({
                    path: "/buyvip",
                    query: {
                        goods_id: item[2].id,
                        goods_name: item[2].name,
                        goods_label: "VIP会员",
                        goods_charge: item[2].charge,
                        goods_type: "role",
                    },
                });
            }
        },
    },
    async created() {
        let res = await this.$request.get("/api/v2/member/detail", {
            params: {},
        });
        this.info = res.data;
        this.name = this.info.role.name;
        let vip = await this.$request.get("/api/v2/roles", {
            params: {},
        });
        this.arr = vip.data;
    },
};
</script>

<style lang="less" scoped>
.head {
    position: fixed;
    top: 0;
    width: 100%;
    height: 50px;
    background-color: #fff;
    z-index: 100;
    padding-left: 15px;
    padding-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #f1f2f6;
    span {
        font-size: 19px;
        position: absolute;
        top: 50%;
        margin-top: -10px;
        left: 4%;
    }
    .title {
        flex: 1;
        font-size: 17px;
        font-weight: 500;
        text-align: center;
        color: #333;
        line-height: 22px;
        overflow: hidden;
    }
}
.container {
    padding-top: 50px;
    background: #f6f6f6;
    position: absolute;
    left: 0;
    top: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    width: 100%;
    height: 100%;
    .info {
        width: 100%;
        display: flex;
        padding: 20px 15px;
        margin-top: 15px;
        margin-bottom: 15px;
        background-color: #fff;
        .left {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
            }
        }
        .right {
            padding-top: 4px;
            margin-left: 15px;
            flex: 1;
            font-size: 13px;
            font-weight: 400;
            color: #333;
            line-height: 20px;
        }
    }
    .item-box {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 15px;
        .item {
            width: calc(50% - 5px);
            padding: 15px;
            box-sizing: border-box;
            border-radius: 8px;
            margin-bottom: 15px;
            border: 1px solid #fff;
            background-color: #fff;
            &.active {
                border: 1px solid #e1a500;
                background: #ffeded;
            }
            .name {
                width: 100%;
                font-size: 14px;
                font-weight: 600;
                color: #e1a500;
                line-height: 14px;
                margin-bottom: 20px;
            }
            .money {
                width: 100%;
                font-size: 28px;
                font-weight: 600;
                color: #333;
                line-height: 24px;
                margin-bottom: 15px;
                span {
                    font-size: 18px;
                }
            }
            .txt {
                width: 100%;
                height: auto;
                float: left;
                font-size: 12px;
                font-weight: 400;
                color: #666;
                line-height: 18px;
            }
        }
    }
    .bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 49px;
        background-color: #cea200;
        line-height: 49px;
        text-align: center;
        color: #fff;
    }
}
</style>
